// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  base: './',

  // 新增 server 配置
  server: {
    proxy: {
      '/api': {  // 代理所有以/api开头的请求
        target: 'https://recruit.aceo.me',  // 后端服务器地址
        changeOrigin: true,  // 允许跨域
        secure: false,  // 关闭SSL验证（仅开发环境）
        rewrite: (path) => path.replace(/^\/api/, '')  // 移除请求路径中的/api前缀
      }
    }
  }
})